//
//  OtherDuobaoView.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/27.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "OtherDuobaoView.h"
#import "RewardsVC.h"
#import "DuoBaoHisVC.h"
#import "ShowOrderVC.h"
#define OTHER_DUOBAO_URL @"/api/ApiUser/viewUserProfile"
@interface OtherDuobaoView ()
{
    __weak IBOutlet UIImageView *headerImg;
    __weak IBOutlet UILabel *countLab;
    __weak IBOutlet UILabel *moneyLab;

    __weak IBOutlet UILabel *lab1;
    __weak IBOutlet UILabel *lab2;
    __weak IBOutlet UILabel *lab3;
}
@end
@implementation OtherDuobaoView

- (void)awakeFromNib
{
    self.backgroundColor = QBB_GRAY_COLOR;
    
    CGFloat yy = WYMHEIGHT/568;
    headerImg.layer.masksToBounds = YES;
    headerImg.layer.borderWidth = 2;
    headerImg.frame = CGRectMake(headerImg.frame.origin.x, headerImg.frame.origin.y-((yy-1)/2)*headerImg.frame.size.height, headerImg.frame.size.width*yy, headerImg.frame.size.height*yy);
    headerImg.layer.borderColor = [[UIColor whiteColor] CGColor];
    headerImg.layer.cornerRadius = headerImg.frame.size.width/2;
    headerImg.layer.masksToBounds = YES;
    headerImg.layer.cornerRadius = headerImg.frame.size.width/2;

    
    CGFloat add = 12;
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(lab1.frame)+add) :WYMWITH :0.5]];
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(lab2.frame)+add) :WYMWITH :0.5]];
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(lab3.frame)+add) :WYMWITH :0.5]];
}
- (void)setUid:(NSString *)uid
{
    _uid = uid;
    NSDictionary *params = @{@"uid":_uid};
    [WYPublic addHudToWindow];
    [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,OTHER_DUOBAO_URL] Parameters:params successBlock:^(NSDictionary *dic) {
        NSNumber *ret = dic[@"ret"];
        if (ret.integerValue == 0) {
            countLab.text = dic[@"data"][@"username"];
            if ([dic[@"data"][@"addr"] class] != [NSNull class]) {
                moneyLab.text = dic[@"data"][@"addr"];
            }else{
                moneyLab.text = @"地址不详";
            }
            NSString *imgUrl = dic[@"data"][@"img_url"];
            [headerImg sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"moren"]];
        }
        [WYPublic removeHudToWindow];
    } failedBlock:^{
        
        [WYPublic removeHudToWindow];
    } needLog:NO];
}

//透明按钮的监听事件
- (IBAction)btnOnClick:(UIButton *)sender {
    switch (sender.tag) {
        case 1:/*****夺宝记录**********/
        {
            DuoBaoHisVC *hisVC = [[DuoBaoHisVC alloc]init];
            hisVC.userId = _uid;
            hisVC.isMyRecordFlag = NO;
            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:hisVC animated:YES];
        }
            break;
        case 2:/*****中奖记录**********/
        {
            RewardsVC *reward = [[RewardsVC alloc]init];
            reward.userId = _uid;
            reward.isMyRecordFlag = NO;
            reward.isOthersFlag = YES;
            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:reward animated:YES];
        }
            break;
        case 3:/*****晒单记录**********/
        {
            ShowOrderVC *showvc = [[ShowOrderVC alloc]init];
            showvc.userId = _uid;
            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:showvc animated:YES];
        }
        default:
            break;
    }
    
}

@end
